#include "LedDrv.h"

//key1 -> ENT1/GPF1  GPFCON[3:2]=0 :input
//key2 -> ENT4/GPF4  GPFCON[9:8]=0 :input
//key3 -> ENT2/GPF2  GPFCON[5:4]=0 :input
//key4 -> ENT0/GPF0  GPFCON[1:0]=0 :input
#define GPFCONF  ((volatile unsigned long*)0x56000050)
#define GPFDATA  ((volatile unsigned long*)0x56000054)

#define KEY1_MASK (0x3 << 2)
#define KEY2_MASK (0x3 << 8)
#define KEY3_MASK (0x3 << 4)
#define KEY4_MASK (0x3 << 0)

#define INTOFFSET (*(volatile unsigned long*)0x4a000014)
#define EINTPEND  (*(volatile unsigned long*)0x560000a8)
#define INTPND    (*(volatile unsigned long*)0X4a000010)
#define SRCPND    (*(volatile unsigned long*)0X4a000000)


int main() {
    init_led();

    while(1) {
    }
    return 0;
}


void int_service() {
    unsigned long w = INTOFFSET;
    switch (w) {
    case 1://EINT1:key1
        set_led(LED_ALL, LED_OFF);//set all leds off
        set_led(LED_1, LED_ON); //led1 on
        break;
    case 4://EINT4-7:key2
        set_led(LED_ALL, LED_OFF);//set all leds off
        set_led(LED_2, LED_ON); //led1 on
        break;
    case 2://EINT2:key3
        set_led(LED_ALL, LED_OFF);//set all leds off
        set_led(LED_3, LED_ON); //led1 on
        break;
    case 0://EINT0:key4
        set_led(LED_ALL, LED_OFF);//set all leds off
        set_led(LED_4, LED_ON); //led1 on
        break;
    default:
        ;
    }

    //clear interupt
    if (4 == w) {
        EINTPEND = (1 << 4);// write EINTPEND.bit4 by 1 to clear interupt.
    }

    SRCPND = (1 << w);
    INTPND = (1 << w);

    return;
}



